package com.hz.ruoyiequipment.warning.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.hz.ruoyiequipment.warning.domain.vo.AgrAlertRecordVo;
import com.hz.ruoyiequipment.warning.service.AgrAlertRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 设备预警记录Controller
 * 
 * @author ruoyi
 * @date 2025-03-09
 */
@RestController
@RequestMapping("/record")
public class AgrAlertRecordController extends BaseController
{
    @Autowired
    private AgrAlertRecordService agrAlertRecordService;

    /**
     * 查询设备预警记录列表
     */
    @RequiresPermissions("warning:abnormal:list")
    @GetMapping("/list")
    public TableDataInfo list(AgrAlertRecordVo agrAlertRecordVo)
    {
        startPage();
        List<AgrAlertRecordVo> list = agrAlertRecordService.selectAgrAlertRecordList(agrAlertRecordVo);
        return getDataTable(list);
    }

    /**
     * 导出设备预警记录列表
     */
    @RequiresPermissions("warning:abnormal:export")
    @Log(title = "设备预警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,  AgrAlertRecordVo agrAlertRecord)
    {
        List< AgrAlertRecordVo> list = agrAlertRecordService.selectAgrAlertRecordList(agrAlertRecord);
        ExcelUtil<AgrAlertRecordVo> util = new ExcelUtil< AgrAlertRecordVo>( AgrAlertRecordVo.class);
        util.exportExcel(response, list, "设备预警记录数据");
    }

    /**
     * 获取设备预警记录详细信息
     */
    @RequiresPermissions("warning:abnormal:query")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(agrAlertRecordService.selectAgrAlertRecordByRecordId(recordId));
    }

    /**
     * 新增设备预警记录
     */
    @RequiresPermissions("warning:abnormal:add")
    @Log(title = "设备预警记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody  AgrAlertRecordVo agrAlertRecord)
    {
        return toAjax(agrAlertRecordService.insertAgrAlertRecord(agrAlertRecord));
    }

    /**
     * 修改设备预警记录
     */
    @RequiresPermissions("warning:abnormal:edit")
    @Log(title = "设备预警记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody  AgrAlertRecordVo agrAlertRecord)
    {
        return toAjax(agrAlertRecordService.updateAgrAlertRecord(agrAlertRecord));
    }

    /**
     * 删除设备预警记录
     */
    @RequiresPermissions("warning:abnormal:remove")
    @Log(title = "设备预警记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(agrAlertRecordService.deleteAgrAlertRecordByRecordIds(recordIds));
    }
}
